package com.jb.web.bean.event;

import com.jb.web.bean.HtmlItem;
import com.jb.web.bean.Page;
import com.jb.web.context.WebContext;


public class ReorderChildren implements UIEventHandler {
    public void handleEvent(WebContext pCtx, UIEvent event) {
        HtmlItem parent = (HtmlItem) event.getSource();
        AJaxEvent evt = (AJaxEvent)event;
        String payload =evt.getPayload();
        Page page = parent.getPage();
        String[] ids = payload.split(",");
        int i=1;
        for(String id : ids) {
            HtmlItem item =(HtmlItem) page.getDescendantByClientId(id);
            parent.addChild(item);
            item.setSequence(i++);
        }
        page.valueChanged(pCtx);
    }
}